home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 1.iso / toolbox / src / exampleCode / opengl / GLUT / lib / glut / strokelex.l < prev   
Encoding:
Lex Description  |  1996-11-11  |  3.0 KB  |  132 lines

  1. %{
  2. /* $XConsortium: lex.l,v 5.4 91/08/26 10:55:26 gildea Exp $ */
  3.  
  4. /*****************************************************************
  5. Copyright (c) 1989,1990, 1991 by Sun Microsystems, Inc. and the X Consortium.
  6.  
  7.                         All Rights Reserved
  8.  
  9. Permission to use, copy, modify, and distribute this software and its 
  10. documentation for any purpose and without fee is hereby granted, 
  11. provided that the above copyright notice appear in all copies and that
  12. both that copyright notice and this permission notice appear in 
  13. supporting documentation, and that the names of Sun Microsystems,
  14. the X Consortium, and MIT not be used in advertising or publicity 
  15. pertaining to distribution of the software without specific, written 
  16. prior permission.  
  17.  
  18. SUN MICROSYSTEMS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 
  19. INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT 
  20. SHALL SUN MICROSYSTEMS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 
  21. DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
  22. WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
  23. ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
  24. SOFTWARE.
  25.  
  26. ******************************************************************/
  27.  
  28.  
  29. #include <stdlib.h>
  30. #include <ctype.h>
  31. #include <math.h>
  32. #include "strokegen.h"
  33.  
  34. #if defined(ISC) && defined(SYSV) && defined(SYSV386) && __STDC__
  35. extern double atof(char *);
  36. #endif
  37.  
  38. #ifdef FLEX_SCANNER
  39. int yylineno;
  40. #endif
  41.  
  42. %}
  43. %%
  44. \'[^']*\' |
  45. \"[^"]*\"        return string(yytext, yyleng);
  46. #.*            ;
  47. [ ,;\t\n]*              /* natural dilimters */ ;
  48.  
  49. [a-zA-Z][a-zA-Z0-9_.]*    {
  50.                 int    token;
  51.                 if (token = res_words(yytext))
  52.                     return token;
  53.                 return string(yytext, yyleng);
  54.              }
  55.  
  56. [+-]?[0-9]+\.?[0-9]*[eE][+-]?[0-9]+ |
  57. [+-]?[0-9]+\.[0-9]*     |
  58. \.[0-9]+        {
  59.                                 yylval.dval = atof(yytext);
  60.                 return REAL;
  61.                         }
  62. [+-]?[0-9]+#[0-9]+    {
  63.                 return INTEGER;
  64.             }
  65. [+-]?[0-9]+        {
  66.                 yylval.ival = atoi(yytext);
  67.                 return INTEGER;
  68.             }
  69. [()]            ;
  70. %%
  71.  
  72. int
  73. res_words(str)
  74. char    str[];
  75. {
  76.     static    struct    res_strct {
  77.         char    *word;
  78.         int    token;
  79.         } res_table[] = {
  80.         {"BOTTOM",        BOTTOM},
  81.         {"CENTER",        CENTER},
  82.                 {"PROPERTIES",          PROPERTIES},
  83.         {"CLOSE",        CLOSE},
  84.         {"FONTNAME",        FONTNAME},
  85.         {"INDEX",        INDEX},
  86.         {"MAGIC",        MAGIC},
  87.         {"OPEN",        OPEN},
  88.         {"RIGHT",        RIGHT},
  89.         {"STROKE",        STROKE},
  90.         {"TOP",            TOP},
  91.         {"VERTICES",        VERTICES},
  92.         {"BEARING",        BEARING},
  93.         {"L_SPACE",        L_SPACE},
  94.         {"WIDTH",        WIDTH},
  95.         {"R_SPACE",        R_SPACE},
  96.         {"NUM_CH",        NUM_CH},
  97.         {0, 0}
  98.         };
  99.  
  100.         {
  101.             register struct res_strct *reserved;
  102.  
  103.             reserved = res_table;
  104.  
  105.             do
  106.                 if (!strcmp(str, reserved->word))
  107.                     break;
  108.             while ((++reserved)->word != 0);
  109.             return reserved->token;
  110.         }
  111. }
  112.  
  113. int
  114. string(str, n)
  115. char    *str;
  116. int    n;
  117. {
  118.     if (*str == '\"' || *str == '\'')
  119.     {
  120.         str++;
  121.         n -= 2;    /* one for EOL, one for end quote */
  122.     }
  123.     if ((yylval.cval = (char *)malloc(n+1)) != NULL)
  124.     {
  125.         strncpy(yylval.cval, str, n);
  126.         yylval.cval[n] = '\0';
  127.         return STRING;
  128.     }
  129.     else
  130.         return 0;
  131. }
  132.